package model;
import java.util.ArrayList;

/*
 * The Bidder class.
 * @author Abdiel Cabrera
 * 
 * This class inherit all fields, getters and setters from its parent
 * class, such as name, userName, password, etc...
 * 
 * Fields added in addition to the parent class: Bid, creditCard
 */

/**
 * Bidder class.
 * 
 * @author Abdiel Cabrera.
 * @version 1.0
 * @date Winter 2014
 */
public class Bidder extends User {

	// accessLevel: 4- Auction Central Employee
	/** The level of this user */
	public static final int MY_LEVEL = 4;

	/** The bids list of this bidder. */
	private ArrayList<Bid> my_bids_list = new ArrayList<Bid>();

	/** The credit card list of this bidder. */
	private CreditCard my_credit_card;
	
	/** Enum user type */
	private UserTypeEnum my_user_type = UserTypeEnum.UT_BIDDER;

	//private Item //my_item;

	/** 
	 * Construct a Bidder object. 
	 * 
	 * @pre the_first_name != null
	 * @pre the_last_name != null
	 * @pre the_userName != null
	 * @pre the_password != null
	 * @pre the_phone != null
	 * @pre the_address != null
	 * @pre the_email != null
	 * 
	 * @param the_first_name The first name
	 * @param the_last_name The last name
	 * @param the_userName The user name
	 * @param the_password The password
	 * @param the_phone The phone
	 * @param the_address The address
	 * @param the_email The e-mail
	 **/
	public Bidder(String the_first_name, String the_last_name, String the_userName, String the_password,
			String the_phone, Address the_address, String the_email) {
		super(the_first_name, the_last_name, the_userName, the_password, the_phone, the_address, the_email,
				MY_LEVEL);
	}

	/**
	 * Blocks a bidder by changing its access level; to -1.
	 * If the access level = -1, the bidder can't place bids.
	 */
	public void blockBidder() {
		super.setMy_accessLevel(-1);
	}

	/**
	 * Returns the credit card list of this Bidder. 
	 * Guarantees a non-null list
	 * 
	 * @post ArrayList<CreditCard> != null
	 * @return the my_creditCard
	 */
	public CreditCard getMy_creditCard() {
		return my_credit_card;
	}

	/**
	 * Place a bid.
	 * @author Bob Landowski
	 * @pre the_bid != null
	 * @pre the_item != null
	 */
	public void placeBid(Bid the_bid){		
		my_bids_list.add(the_bid);
	}

	/**
	 * Cancel bid.
	 * 
	 * @pre the_item != null
	 */
	public void cancelBid(Item the_Item_to_remove_from){
		// we want to remove all bids by this bidder from an specific item
		ArrayList<Bid> bids_to_remove_from = new ArrayList<Bid>();
		the_Item_to_remove_from.get_Bid_History().addAll(bids_to_remove_from);

		// Removes from this list all of its elements that are 
		// contained in the specified collection:
		bids_to_remove_from.removeAll(my_bids_list);
	}

	/**
	 * Adds a credit card to the list of credit cards for 
	 * the Bidder object. 
	 * 
	 * @pre the_credit_card != null
	 */
	public void addCreditCard(CreditCard the_credit_card){
		my_credit_card = the_credit_card;
	}

	/**
	 * Removes a credit card from the list of credit cards.
	 * 
	 * @pre the_credit_card != null
	 */
	public void removeCreditCard(){
		my_credit_card = null;
	}

	/**
	 * Update a credit card.
	 * 
	 * @pre old_credit_card != null
	 * @pre new_credit_card != null
	 * 
	 * @param old_credit_card the credit card to be updated
	 * @param new_credit_card the new credit card to update from
	 */
	public void updateCreditCard(CreditCard new_credit_card){
		my_credit_card = new_credit_card;
	}

	/**
	 * Returns the list of Bids of this Bidder.
	 * 
	 *  @post ArrayList<Bid> != null
	 */
	public ArrayList<Bid> findBids(){
		return my_bids_list;
	}
	
	/**
	 * Returns the user type.
	 * 
	 * @return the my_user_type
	 */
	public UserTypeEnum get_userType() {
		return my_user_type;
	}
	
	/**
	 * Returns a String representation of the Bidder object.
	 * 
	 * @return a String representation.
	 */
	public String toString() {
		String result;
		result = my_first_name + "~" + my_last_name + "~" + my_userName + "~" + my_password
				 + "~" + my_phone + "~addressObject~" + my_email;
		return result;
	}
}
